package com.example.listviewtest;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;

public class RecyclerActivity extends AppCompatActivity {
    RecyclerView recyclerView;
    ArrayList<Animal> animals = new ArrayList<>();
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.recycler_view);
        recyclerView = findViewById(R.id.recyclerView);
        initData();
        AnimalRecyclerAdapter animalAdapter = new AnimalRecyclerAdapter(animals);
        GridLayoutManager gridLayoutManager = new GridLayoutManager(this,4);
        recyclerView.setAdapter(animalAdapter);
        recyclerView.setLayoutManager(gridLayoutManager);
    }

    private void initData() {
        for(int i = 0; i < 100; i++){
            Animal animal = new Animal(R.drawable.animal,String.valueOf(i));
            animals.add(animal);
        }
    }
}
